//
//  PersonCenterCellView.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/8/3.
//  Copyright (c) 2015年 szb. All rights reserved.
//

#import "PersonCenterCellView.h"
#import "PersonCenterItem.h"
#import "PCArrowItm.h"
#import "PCLabelItem.h"


@interface PersonCenterCellView ()
//箭头
@property (nonatomic,strong)UIImageView *rightArrow;
//文字
@property (nonatomic,strong)UILabel *rightLabel;

@end

@implementation PersonCenterCellView

- (UIImageView *)rightArrow
{
    if (_rightArrow == nil) {
        self.rightArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"personCenterArrow"]];
    }
    return _rightArrow;
}

- (UIView *)rightLabel
{
    if (_rightLabel == nil) {
        self.rightLabel = [[UILabel alloc] init];
    }
    return _rightLabel;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"common";
    PersonCenterCellView *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[PersonCenterCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        // 设置标题的字体
        self.textLabel.font = [UIFont systemFontOfSize:15];
        self.detailTextLabel.font = [UIFont systemFontOfSize:11];
        
        // 去除cell的默认背景色
        self.backgroundColor = [UIColor clearColor];
        
        // 设置背景view
        self.backgroundView = [[UIImageView alloc] init];
        self.selectedBackgroundView = [[UIImageView alloc] init];
    }
    return self;
}

- (void)setItem:(PersonCenterItem *)item
{
    _item = item;
    if (item.icon != nil) {
        self.imageView.image = [UIImage imageNamed:item.icon];
    }
    self.textLabel.text = item.title;
    
    if ([item isKindOfClass:[PCArrowItm class]]) {
        self.accessoryView = self.rightArrow;
    }else if([item isKindOfClass:[PCLabelItem class]]){
        PCLabelItem *labelItem = (PCLabelItem *)item;
        self.rightLabel.text = labelItem.text;
        self.rightLabel.textColor = BPGlobaThemeColor;
        self.rightLabel.size = [labelItem.text sizeWithFont:self.rightLabel.font];
        self.accessoryView = self.rightLabel;
    }else{
        self.accessoryView = nil;
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
